local GC_Sniffer = CreateFrame("Frame")
GC_Sniffer:RegisterEvent("CHAT_MSG_GUILD")
GC_Sniffer:SetScript("OnEvent", function (self, event, message, sender)
--команды для управления квестами
local nik=sender
local endQuests="простые_квесты"
local qAchiv="взят_ли_квест_простая_ачивка"
nachaloStr=mysplit(message)
nachaloStr = string.utf8sub(nachaloStr[1], 1, 1)
local hshStran3S
local hshStranMsgS
local hshStranMsgS2
local hshStranS1
local hshStranS2
local hshStranMsgS1
local msg = mysplit(message)
local myNome = GetUnitName("player")
hshStranMsgS=mysplit(message)
testGM=gmTest(sender)
hshStranMsgS2=string.sub(message,7,7)
local msgMB=mysplit(message)
if string.find (message, "#") and hshStranMsgS[2]~= nil and nachaloStr~="*" then
	hshStranMsgS1=hshStranMsgS[1]
	hshStranS1,hshStranS2=hshStrNuovoServ(hshStranMsgS1,sender)

end
hshStran3S=hshSenderNomeServ(sender)
if TDG == nil then
	TDG = {}
end
if TDG["лвлап"] ~= nil then
	for k, v in pairs(TDG["лвлап"]) do
		print(v)
	end
end

if TDG[sender]==nil then
	TDG[sender]={}
end

if msg[1] == "!3лвл" then
	SendChatMessage(msg[2] .. ", выбери что то одно из пятой ячейки гб, КРОМЕ маунтов, серой кошки, письма. ИЛИ лотерейный билет.", "officer", nil, 1)
end

if string.find (message, "буриданов_осел") and string.find (message, "СТАРТ") and testGM~=nil then
	genRand10()
end
if msg[1] == "!аддон" then
	SendChatMessage(sender .. ", скачай файл: https://u.to/3VD4Hw", "officer", nil, 1)
	SendChatMessage(sender .. ", запусти, дождись пока скажет, что все успешно завершено и перезапусти игру", "officer", nil, 1)
end
vZH = mysplit(message)

if vZH[2] == nil then
if string.find (message, "ВОЖДЬ") or string.find (message, "#zzx") then
if nachaloStr~="*" then
	if sender == "Нейру" then
		if TDG["Нейру"]["напоминалка"] == nil then
			TDG["Нейру"]["напоминалка"] = 342
		else
			TDG["Нейру"]["напоминалка"] = tonumber(TDG["Нейру"]["напоминалка"])
			TDG["Нейру"]["напоминалка"] = TDG["Нейру"]["напоминалка"]+1
			SendChatMessage("*" .. sender .. ", я тебе уже " .. TDG["Нейру"]["напоминалка"] .. " раз говорил, что у тебя уже есть квест.", "officer", nil, 1)
			SendChatMessage("И что тебе доступны квесты через аддон, кроме жабы.", "officer", nil, 1)
		end
	else
	for guokZ=1,GetNumGuildMembers(true) do
		local name, rankName, rankIndex, level, classDisplayName, zone, publicNote, officerNote, isOnline, status, class, achievementPoints, achievementRank, isMobile, canSoR, repStanding, guid = GetGuildRosterInfo(guokZ)
		if name == sender then
			local denT = string.utf8sub(officerNote, 6, 7)
			local qN = string.utf8sub(officerNote, 8, 8)
			local gildLvl = string.utf8sub(officerNote, 1, 1)
			qN = tonumber (qN)
			denn = {}
			denn = date("%d")
			denn = tonumber(denn)
			denT = tonumber(denT)
			gildLvl = tonumber (gildLvl)
			if denn == denT then
				if qN >= gildLvl then
					local msgQ = mysplit(message)
					if msgQ[2] == versAdd then
						SendChatMessage(sender .. ", следущий квест на твоем гильдлвле доступен завтра, но тебе доступен дополнительный квест с повышенным опытом: вторая кнопка", "officer", nil, 1)
					end
					if msgQ[2] == nil then
						SendChatMessage(sender .. ", следущий квест на твоем гильдлвле доступен завтра", "officer", nil, 1)
						SendChatMessage(sender .. ", Но ты можешь установить аддон (читай информацию о гильдии) и получить бонусный квест.", "officer", nil, 1)
					end
					if msgQ[2] ~= versAdd and msgQ[2] ~= nil then
						SendChatMessage(sender .. ", следущий квест на твоем гильдлвле доступен завтра, но тебе доступен дополнительный квест с повышенным опытом: вторая кнопка", "officer", nil, 1)
						SendChatMessage(sender .. ", так же ты можешь обновить аддон и воспользоваться дополнительным квестом за акутальную версию", "officer", nil, 1)
					end
				else
					SendChatMessage("*" .. nik .. ", простой или сложный?", "officer", nil, 1)
				end
			else
				SendChatMessage("*" .. nik .. ", простой или сложный?", "officer", nil, 1)
			end
		else
		end
	end
	end
end
end
end
--показать инфу об игроке
local guokInf = string.gsub(message, "%s+", "")
if string.find (guokInf, "!гильдлвл") or string.find (message, "#zzt") and nachaloStr~="*" then
	for guok=1,GetNumGuildMembers(true) do
		local name, rankName, rankIndex, level, classDisplayName, zone, publicNote, officerNote, isOnline, status, class, achievementPoints, achievementRank, isMobile, canSoR, repStanding, guid = GetGuildRosterInfo(guok)
		if name == sender then
			local gildLvl = string.utf8sub(officerNote, 1, 1)
			local gildExp = string.utf8sub(officerNote, 2, 5)
			SendChatMessage("*" .. sender .. ": " .. gildLvl .. " гильдлвл" .. " и " .. gildExp .. " опыта", "officer", nil, 1)
			local gildLvlN = tonumber (gildLvl)
			local gildExpN = tonumber (gildExp)
			if gildLvl == "0" then
				local gildExpN = 4 - gildExpN
				SendChatMessage("*" .. sender .. ": до лвлапа осталось " .. gildExpN .. " опыта" , "officer", nil, 1)
			elseif gildLvl == "1" then
				local gildExpN = 8 - gildExpN
				SendChatMessage("*" .. sender .. ": до лвлапа осталось " .. gildExpN .. " опыта" , "officer", nil, 1)
			elseif gildLvl == "2" then
				local gildExpN = 16 - gildExpN
				SendChatMessage("*" .. sender .. ": до лвлапа осталось " .. gildExpN .. " опыта" , "officer", nil, 1)
			elseif gildLvl == "3" then
				local gildExpN = 32 - gildExpN
				SendChatMessage("*" .. sender .. ": до лвлапа осталось " .. gildExpN .. " опыта" , "officer", nil, 1)
			elseif gildLvl == "4" then
				local gildExpN = 64 - gildExpN
				SendChatMessage("*" .. sender .. ": до лвлапа осталось " .. gildExpN .. " опыта" , "officer", nil, 1)
			elseif gildLvl == "5" then
				local gildExpN = 128 - gildExpN
				SendChatMessage("*" .. sender .. ": до лвлапа осталось " .. gildExpN .. " опыта" , "officer", nil, 1)
			elseif gildLvl == "6" then
				local gildExpN = 256 - gildExpN
				SendChatMessage("*" .. sender .. ": до лвлапа осталось " .. gildExpN .. " опыта" , "officer", nil, 1)
			elseif gildLvl == "7" then
				local gildExpN = 512 - gildExpN
				SendChatMessage("*" .. sender .. ": до лвлапа осталось " .. gildExpN .. " опыта" , "officer", nil, 1)
			elseif gildLvl == "8" then
				local gildExpN = 1024 - gildExpN
				SendChatMessage("*" .. sender .. ": до лвлапа осталось " .. gildExpN .. " опыта" , "officer", nil, 1)
			elseif gildLvl == "9" then
				local gildExpN = 2048 - gildExpN
				SendChatMessage("*" .. sender .. ": до лвлапа осталось " .. gildExpN .. " опыта" , "officer", nil, 1)
			end
		else
		end
	end
else
end
if msgMB[1] == "!ик" then
	if string.find(message,"…ик!",1,true) then
		SendChatMessage(sender .. " получает 50 золота", "officer", nil, 1)
	else
		SendChatMessage(sender .. " должен гильдии 10 золота", "officer", nil, 1)
	end
end
if msgMB[1] == "!рб" and msgMB[2] == "старт" and TDG["mb"] == nil then
	TDG["mb"] = {}
	TDG["mb"][1] = {}
	TDG["mb"][2] = {}
	TDG["mb"][3] = {}
	TDG["mb"][4] = {}
	TDG["mb"][5] = {}
	local i = 1
	while true do
		if i >= 60 then
			break
		end
		local ii = math.random(1,256)
		if TDG["mb"][1][ii] == nil and TDG["mb"][1][ii+1] == nil and TDG["mb"][1][ii-1] == nil then
			TDG["mb"][1][ii] = 1
			i = i + 1
		end
	end
end
if msgMB[1] == "!рб" and msgMB[2] ~= "старт" and tonumber(msgMB[2]) >=1 and tonumber(msgMB[2]) <=256 then
	local t
	if TDG["mb"] ~= nil then
		if TDG["mb"][sender] == nil then
			if TDG["mb"]["pd"] == nil then
				TDG["mb"]["pd"] = 0
			end
			if TDG["mb"]["игроки"] == nil then
				TDG["mb"]["игроки"] = {}
			end
			if TDG["mb"]["игроки"][sender] == nil then
				TDG["mb"]["игроки"][sender] = {}
			end
			if TDG["mb"]["игроки"][sender]["hp"] == nil then
				TDG["mb"]["игроки"][sender]["hp"] = 100
			end
			if TDG["mb"]["игроки"][sender]["dinero"] == nil then
				TDG["mb"]["игроки"][sender]["dinero"] = 0
			end
		end
		for k=1,256 do
			if TDG["mb"][1][k] == 1 and k == tonumber(msgMB[2]) then
				if t == nil then
					t = "@"
				else
					t = t .. "@"
				end
				TDG["mb"]["игроки"][sender]["dinero"] = TDG["mb"]["игроки"][sender]["dinero"] + 30
				SendChatMessage("БЗДЫЩ!!1 " .. sender .. " уничтожает подводную лодку!", "officer", nil, 1);
				TDG["mb"]["игроки"][sender]["hp"] = TDG["mb"]["игроки"][sender]["hp"] + 20
				TDG["mb"][1][k] = 2
				if TDG["mb"]["pd"] == nil then
					TDG["mb"]["pd"] = 1
				else
					TDG["mb"]["pd"] = TDG["mb"]["pd"] + 1
				end
			end
			if TDG["mb"][1][k] ~= 1 and TDG["mb"][1][k] ~= 2 and TDG["mb"][1][k] ~= 3 and k == tonumber(msgMB[2]) then
				if t == nil then
					t = "#"
				else
					t = t .. "#"
				end
				TDG["mb"]["игроки"][sender]["dinero"] = TDG["mb"]["игроки"][sender]["dinero"] - 10
				TDG["mb"][1][k] = 3
			end
			if TDG["mb"][1][k] ~= 1 and TDG["mb"][1][k] ~= 2 and TDG["mb"][1][k] ~= 3 and k ~= tonumber(msgMB[2]) then
				if t == nil then
					t = "~"
				else
					t = t .. "~"
				end
			end
			if TDG["mb"][1][k] == 1 and k ~= tonumber(msgMB[2]) then
				if t == nil then
					t = "~"
				else
					t = t .. "~"
				end
			end
			if TDG["mb"][1][k] == 2 then
				if t == nil then
					t = "*"
				else
					t = t .. "*"
				end
			end
			if TDG["mb"][1][k] == 3 then
				if t == nil then
					t = "X"
				else
					t = t .. "X"
				end
			end
		end
		for o = 1, 60-tonumber(TDG["mb"]["pd"]) do
			local kill = math.random(1,100)
			if kill <= 10 then
				TDG["mb"]["игроки"][sender]["hp"]=TDG["mb"]["игроки"][sender]["hp"]-1
			end
			if TDG["mb"]["игроки"][sender]["hp"] <= 0 then
				if TDG["mb"]["игроки"][sender]["dinero"] < 0 then
					SendChatMessage(sender .. " уничтожен и должен гильдии " .. TDG["mb"]["игроки"][sender]["dinero"] .. " золота", "officer", nil, 1);
				else
					SendChatMessage(sender .. " уничтожен", "officer", nil, 1);
				end
				TDG["mb"]["игроки"][sender] = nil
				break
			end
		end
		SendChatMessage(t, "officer", nil, 1);
		if TDG["mb"]["игроки"][sender] ~= nil then
			SendChatMessage(sender .. ": " .. TDG["mb"]["игроки"][sender]["dinero"] .. " золота и " .. TDG["mb"]["игроки"][sender]["hp"] .. " здоровья" , "officer", nil, 1);

			if TDG["mb"]["pd"] >= 60 then
				for k, v in pairs(TDG["mb"]["игроки"]) do
					SendChatMessage(k .. ": " .. TDG["mb"]["игроки"][k]["dinero"] .. " золота", "officer", nil, 1);
				end
				TDG["mb"] = nil
			end
		end
	end
end

if string.find (message, "ВОЖДЬ, хочу больше квестов и опыта!!!") or string.find (message, "#zz1") and nachaloStr~="*" then
	if TDG[sender]["доп_квест"]==nil or TDG[sender]["доп_квест"]==9999 then
		local kol=0
		for guokZ=1,GetNumGuildMembers(true) do
			local name, rankName, rankIndex, level, classDisplayName, zone, publicNote, officerNote, isOnline, status, class, achievementPoints, achievementRank, isMobile, canSoR, repStanding, guid = GetGuildRosterInfo(guokZ)
			kol=kol+1
		end
		local kol1=kol+20
		if kol <= 980 then
			SendChatMessage(hshStran3S .. " " .. "#zzl " .. sender .. ", сейчас в гильдии " .. kol .. " игроков. Должно стать " .. kol1, "officer", nil, 1);
			TDG[sender]["доп_квест"]=kol1
		else
			SendChatMessage("Дополнительный квест временно недоступен. Ждите Кусяо.", "officer", nil, 1);
		end
	else
	poluchenoKolichestvo=TDG[sender]["доп_квест"]
	SendChatMessage("*" .. sender .. ", у тебя уже есть квест. Для выполнения в гильдии должно стать " .. poluchenoKolichestvo .. " игроков.", "officer", nil, 1);
	end
end

if string.find (message, "ВОЖДЬ, сдать доп квест!!!") or string.find (message, "#zzy") and nachaloStr~="*" then
	if TDG[sender]["доп_квест"]~=nil and TDG[sender]["доп_квест"]~=9999 then
		local kol=0
		for guokZ=1,GetNumGuildMembers(true) do
		local name, rankName, rankIndex, level, classDisplayName, zone, publicNote, officerNote, isOnline, status, class, achievementPoints, achievementRank, isMobile, canSoR, repStanding, guid = GetGuildRosterInfo(guokZ)
		kol=kol+1
		end
		rezDopQuest=TDG[sender]["доп_квест"]
		if rezDopQuest>kol then
			SendChatMessage("*" .. sender .. ", сейчас в гильдии " .. kol .. " игроков. Должно стать " .. rezDopQuest, "officer", nil, 1);
		else
			SendChatMessage(sender .. " получает 3 опыта", "guild", nil, 1);
			SendChatMessage("*" .. sender .. " получает кусок карты (за куском обращаться отдельно.", "officer", nil, 1);
			if TDG[sender]["кусков_карты"]==nil then
				TDG[sender]["кусков_карты"]=1
			else
				dopKus=TDG[sender]["кусков_карты"]
				dopKus=tonumber(dopKus)
				dopKus=dopKus+1
				TDG[sender]["кусков_карты"]=dopKus
			end
			TDG[sender]["доп_квест"]=9999
		end
	else
		SendChatMessage("*" .. sender .. ", сначала нужно взять квест", "officer", nil, 1);
	end
end
--справка
    if string.find (message, "ВОЖДЬ инфо") or string.find (message, "#info")  and nachaloStr~="*" then
		SendChatMessage("*Получить квест: ВОЖДЬ", "officer", nil, 1)
		--SendChatMessage("*Заполнить заметку: !заметка Текст заметки" , "officer", nil, 1)
		SendChatMessage("*Дополнить существующую системную заметку: !заметка+ Текст заметки" , "officer", nil, 1)
	else
	end


if string.find (message, "Я вернулся на маршрут") and nachaloStr~="*" then


	if hshStranS1==hshStranS2 then
		SendChatMessage(sender .. " получает 1 опыта", "guild", nil, 1)
	end
end
local msg = mysplit(message)
if msg[1] == "!х" and msg[2] ~= nil then
	local q = tostring(msg[2])
	if TDG["xo"] == nil then
		TDG["xo"] = {}
	end
	if TDG["xo"][q] ~= 1 and TDG["xo"][q] ~= 2 then
		TDG["xo"][q] = 1
			if TDG["xo"]["1"] == 1 then
				q1 = "x"
			elseif TDG["xo"]["1"] == 2 then
				q1 = "о"
			else
				q1 = "_"
			end
			if TDG["xo"]["2"] == 1 then
				q2 = "x"
			elseif TDG["xo"]["2"] == 2 then
				q2 = "о"
			else
				q2 = "_"
			end
			if TDG["xo"]["3"] == 1 then
				q3 = "x"
			elseif TDG["xo"]["3"] == 2 then
				q3 = "о"
			else
				q3 = "_"
			end
			if TDG["xo"]["4"] == 1 then
				q4 = "x"
			elseif TDG["xo"]["4"] == 2 then
				q4 = "о"
			else
				q4 = "_"
			end
			if TDG["xo"]["5"] == 1 then
				q5 = "x"
			elseif TDG["xo"]["5"] == 2 then
				q5 = "о"
			else
				q5 = "_"
			end
			if TDG["xo"]["6"] == 1 then
				q6 = "x"
			elseif TDG["xo"]["6"] == 2 then
				q6 = "о"
			else
				q6 = "_"
			end
			if TDG["xo"]["7"] == 1 then
				q7 = "x"
			elseif TDG["xo"]["7"] == 2 then
				q7 = "о"
			else
				q7 = "_"
			end
			if TDG["xo"]["8"] == 1 then
				q8 = "x"
			elseif TDG["xo"]["8"] == 2 then
				q8 = "о"
			else
				q8 = "_"
			end
			if TDG["xo"]["9"] == 1 then
				q9 = "x"
			elseif TDG["xo"]["9"] == 2 then
				q9 = "о"
			else
				q9 = "_"
			end
		qxx1=q1 .. q2 .. q3
		qxx2=q4 .. q5 .. q6
		qxx3=q7 .. q8 .. q9
		SendChatMessage(" " .. qxx1, "officer", nil, 1)
		SendChatMessage(" " .. qxx2, "officer", nil, 1)
		SendChatMessage(" " .. qxx3, "officer", nil, 1)
		end

	if TDG["xo"] ~= nil and TDG["xo"]["1"] == 1 and TDG["xo"]["2"] == 1 and TDG["xo"]["3"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["1"] == 1 and TDG["xo"]["4"] == 1 and TDG["xo"]["7"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["1"] == 1 and TDG["xo"]["5"] == 1 and TDG["xo"]["9"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["3"] == 1 and TDG["xo"]["5"] == 1 and TDG["xo"]["7"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["4"] == 1 and TDG["xo"]["5"] == 1 and TDG["xo"]["6"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["7"] == 1 and TDG["xo"]["8"] == 1 and TDG["xo"]["9"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["2"] == 1 and TDG["xo"]["5"] == 1 and TDG["xo"]["8"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["3"] == 1 and TDG["xo"]["6"] == 1 and TDG["xo"]["9"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["1"] == 2 and TDG["xo"]["2"] == 2 and TDG["xo"]["3"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["1"] == 2 and TDG["xo"]["4"] == 2 and TDG["xo"]["7"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["1"] == 2 and TDG["xo"]["5"] == 2 and TDG["xo"]["9"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["3"] == 2 and TDG["xo"]["5"] == 2 and TDG["xo"]["7"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["4"] == 2 and TDG["xo"]["5"] == 2 and TDG["xo"]["6"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["7"] == 2 and TDG["xo"]["8"] == 2 and TDG["xo"]["9"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["2"] == 2 and TDG["xo"]["5"] == 2 and TDG["xo"]["8"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["3"] == 2 and TDG["xo"]["6"] == 2 and TDG["xo"]["9"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil then
		local xxx
		for i=1,9 do
			local j = tostring(i)
			if TDG["xo"][j] ~= 1 and TDG["xo"][j] ~= 2 then
				xxx = 1
				break
			else
				xxx = 0
			end
		end
		if xxx ~= 1 then
			SendChatMessage("ничья", "officer", nil, 1)
			TDG["xo"] = nil
		end
	end
end
local msg = mysplit(message)
if msg[1] == "!о" and msg[2] ~= nil then
	local q = tostring(msg[2])
	if TDG["xo"] == nil then
		TDG["xo"] = {}
	end
	if TDG["xo"][q] ~= 1 and TDG["xo"][q] ~= 2 then
		TDG["xo"][q] = 2
			if TDG["xo"]["1"] == 2 then
				q1 = "о"
			elseif TDG["xo"]["1"] == 1 then
				q1 = "x"
			else
				q1 = "_"
			end
			if TDG["xo"]["2"] == 2 then
				q2 = "о"
			elseif TDG["xo"]["2"] == 1 then
				q2 = "x"
			else
				q2 = "_"
			end
			if TDG["xo"]["3"] == 2 then
				q3 = "о"
			elseif TDG["xo"]["3"] == 1 then
				q3 = "x"
			else
				q3 = "_"
			end
			if TDG["xo"]["4"] == 2 then
				q4 = "о"
			elseif TDG["xo"]["4"] == 1 then
				q4 = "x"
			else
				q4 = "_"
			end
			if TDG["xo"]["5"] == 2 then
				q5 = "о"
			elseif TDG["xo"]["5"] == 1 then
				q5 = "x"
			else
				q5 = "_"
			end
			if TDG["xo"]["6"] == 2 then
				q6 = "о"
			elseif TDG["xo"]["6"] == 1 then
				q6 = "x"
			else
				q6 = "_"
			end
			if TDG["xo"]["7"] == 2 then
				q7 = "о"
			elseif TDG["xo"]["7"] == 1 then
				q7 = "x"
			else
				q7 = "_"
			end
			if TDG["xo"]["8"] == 2 then
				q8 = "о"
			elseif TDG["xo"]["8"] == 1 then
				q8 = "x"
			else
				q8 = "_"
			end
			if TDG["xo"]["9"] == 2 then
				q9 = "о"
			elseif TDG["xo"]["9"] == 1 then
				q9 = "x"
			else
				q9 = "_"
			end
		qxx1=q1 .. q2 .. q3
		qxx2=q4 .. q5 .. q6
		qxx3=q7 .. q8 .. q9
		SendChatMessage(" " .. qxx1, "officer", nil, 1)
		SendChatMessage(" " .. qxx2, "officer", nil, 1)
		SendChatMessage(" " .. qxx3, "officer", nil, 1)
	end
	if TDG["xo"] ~= nil and TDG["xo"]["1"] == 1 and TDG["xo"]["2"] == 1 and TDG["xo"]["3"] == 1 then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["1"] == 1 and TDG["xo"]["4"] == 1 and TDG["xo"]["7"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["1"] == 1 and TDG["xo"]["5"] == 1 and TDG["xo"]["9"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["3"] == 1 and TDG["xo"]["5"] == 1 and TDG["xo"]["7"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["4"] == 1 and TDG["xo"]["5"] == 1 and TDG["xo"]["6"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["7"] == 1 and TDG["xo"]["8"] == 1 and TDG["xo"]["9"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["2"] == 1 and TDG["xo"]["5"] == 1 and TDG["xo"]["8"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["3"] == 1 and TDG["xo"]["6"] == 1 and TDG["xo"]["9"] == 1  then
		SendChatMessage("x победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["1"] == 2 and TDG["xo"]["2"] == 2 and TDG["xo"]["3"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["1"] == 2 and TDG["xo"]["4"] == 2 and TDG["xo"]["7"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["1"] == 2 and TDG["xo"]["5"] == 2 and TDG["xo"]["9"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["3"] == 2 and TDG["xo"]["5"] == 2 and TDG["xo"]["7"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["4"] == 2 and TDG["xo"]["5"] == 2 and TDG["xo"]["6"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["7"] == 2 and TDG["xo"]["8"] == 2 and TDG["xo"]["9"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["2"] == 2 and TDG["xo"]["5"] == 2 and TDG["xo"]["8"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil and TDG["xo"]["3"] == 2 and TDG["xo"]["6"] == 2 and TDG["xo"]["9"] == 2  then
		SendChatMessage("о победил ", "officer", nil, 1)
		TDG["xo"] = nil
	end
	if TDG["xo"] ~= nil then
		local xxx
		for i=1,9 do
		local j = tostring(i)
			if TDG["xo"][j] ~= 1 and TDG["xo"][j] ~= 2 then
				xxx = 1
				break
			else
				xxx = 0
			end
		end
		if xxx ~= 1 then
			SendChatMessage("ничья", "officer", nil, 1)
			TDG["xo"] = nil
		end
	end
end

local mSg = mysplit(message)
if mSg[2] == nil and string.find (message, "!хо") then
	if  TDG["xo"] ~= nil then
		if TDG["xo"]["1"] == 2 then
			q1 = "о"
		elseif TDG["xo"]["1"] == 1 then
			q1 = "x"
		else
			q1 = "_"
		end
		if TDG["xo"]["2"] == 2 then
			q2 = "о"
		elseif TDG["xo"]["2"] == 1 then
			q2 = "x"
		else
			q2 = "_"
		end
		if TDG["xo"]["3"] == 2 then
			q3 = "о"
		elseif TDG["xo"]["3"] == 1 then
			q3 = "x"
		else
			q3 = "_"
		end
		if TDG["xo"]["4"] == 2 then
			q4 = "о"
		elseif TDG["xo"]["4"] == 1 then
			q4 = "x"
		else
			q4 = "_"
		end
		if TDG["xo"]["5"] == 2 then
			q5 = "о"
		elseif TDG["xo"]["5"] == 1 then
			q5 = "x"
		else
			q5 = "_"
		end
		if TDG["xo"]["6"] == 2 then
			q6 = "о"
		elseif TDG["xo"]["6"] == 1 then
			q6 = "x"
		else
			q6 = "_"
		end
		if TDG["xo"]["7"] == 2 then
			q7 = "о"
		elseif TDG["xo"]["7"] == 1 then
			q7 = "x"
		else
			q7 = "_"
		end
		if TDG["xo"]["8"] == 2 then
			q8 = "о"
		elseif TDG["xo"]["8"] == 1 then
			q8 = "x"
		else
			q8 = "_"
		end
		if TDG["xo"]["9"] == 2 then
			q9 = "о"
		elseif TDG["xo"]["9"] == 1 then
			q9 = "x"
		else
			q9 = "_"
		end
		qxx1=q1 .. q2 .. q3
		qxx2=q4 .. q5 .. q6
		qxx3=q7 .. q8 .. q9
		SendChatMessage(" " .. qxx1, "officer", nil, 1)
		SendChatMessage(" " .. qxx2, "officer", nil, 1)
		SendChatMessage(" " .. qxx3, "officer", nil, 1)
	end
end

ltr=mysplit(message)
if string.find (message, "получает лотерейный билет") and testGM~=nil then
	ltrNik=ltr[1]
	if TDG[ltrNik]["лотерея"]==nil then
		TDG[ltrNik]["лотерея"]=3
	else
		lotereya=TDG[ltrNik]["лотерея"]
		lotereya=lotereya+3
		TDG[ltrNik]["лотерея"]=lotereya
	end
end
if string.find (message, "награда за гильдлвл !выдана") and testGM~=nil then
	local msg = mysplit(message)
	TDG["лвлап"][msg[1]] = nil
end

--возможность игроку писать свою заметку
testHis=mysplit(message)
testHis[1]=all_trim(testHis[1])
--[[if testHis[1] == "!zаметка" or string.find (message, "#zzv") and nachaloStr~="*" then
	local vz = (message):gsub("!заметка ", "");
	for z=1,GetNumGuildMembers(true) do
		local name, rankName, rankIndex, level, classDisplayName, zone, publicNote, officerNote, isOnline, status, class, achievementPoints, achievementRank, isMobile, canSoR, repStanding, guid = GetGuildRosterInfo(z)
		if name == sender then
			GuildRosterSetPublicNote(z, vz)
			SendChatMessage("*" .. name .. ", заметка добавлена", "officer", nil, 1)
		else
		end
	end
end--]]

if msg[1] == "!заметка" then
	local zametka = msg[2]
	if msg[3] ~= nil then
		for i=3,#msg do
			zametka = zametka .. " " .. msg[i]
		end
	end
	TDG[sender]["заметка"] = zametka
	SendChatMessage(sender .. " заметка добавлена", "officer", nil, 1)
end
if msg[1] == "!ЗАМЕТКА" then
	local zametka = msg[2]
	if TDG[sender]["заметка"] ~= nil then
		if msg[3] ~= nil then
			for i=3,#msg do
				zametka = zametka .. " " .. msg[i]
			end
		end
		zametka = TDG[sender]["заметка"] .. "\n" .. zametka
		TDG[sender]["заметка"] = zametka
		SendChatMessage(sender .. " заметка дополнена", "officer", nil, 1)
	end
end

if msg[1] == "!отзыв" then
	if msg[2] ~= nil then
		if msg[3] ~= nil then
			local zametka = "|cFF6495EDОт " .. sender .. ": |cff99ff99" .. msg[3]
			if msg[4] ~= nil then
				for i=4,#msg do
					zametka = zametka .. " " .. msg[i]
				end
			end
			if TDG[msg[2]] == nil then
				TDG[msg[2]] = {}
			end
			if TDG[msg[2]]["отзыв"] == nil then
				TDG[msg[2]]["отзыв"] = zametka .. "\n"
			else
				TDG[msg[2]]["отзыв"] = TDG[msg[2]]["отзыв"] .. zametka .. "\n"
			end
			SendChatMessage(sender .. " отзыв о персонаже " .. msg[2] .. " добавлен", "officer", nil, 1)
		else
			SendChatMessage(sender .. ", отзыв не должен быть пустым", "officer", nil, 1)
		end
	else
		SendChatMessage(sender .. ", не указано кому добавлять отзыв", "officer", nil, 1)
	end
end

local messag = string.lower(message)
local msg = mysplit(messag)
if msg[1] == "!внимание," and nachaloStr~="*" then
print ("1")
	TDG["вопрос"] = message
	print (TDG["вопрос"])
end
if (msg[1] == "!в" or msg[1] == "!вопрос") and nachaloStr~="*" then
	if TDG["вопрос"] ~= nil then
		SendChatMessage(TDG["вопрос"], "officer", nil, 1)
	end
end
if (msg[1] == "!б" or msg[1] == "!буква") and nachaloStr~="*" then
	if TDG["vikUch"]~= nil then
		tempB = TDG["vikUch"][sender]
	end
	local r = nil
	if TDG["vik"] ~= nil then
		if msg[2] ~= nil then
			local numS = string.utf8len(msg[2])
			if numS == 1 then
				if TDG["vikUch"] == nil then
					TDG["vikUch"] = {}
				end
				if string.len(TDG["vik"]) > 1 then
					local s
					local bally = 0
					local p = 0
					local msg = mysplit(messag)
					local stroka = {}
					if TDG["vik"]~=nil then
						s = ssplit(TDG["vik"])
					end
					for i=1,#s do
						if TDG["s"] == nil then
							TDG["s"] = {}
						end
						if TDG["s"][i] == nil then
							if s[i] == msg[2] then
								stroka[i] = msg[2]
								TDG["s"][i] = msg[2]
								bally = bally + 1
							else
								stroka[i] = "*"
								p = 1
							end
						else
							stroka[i] = TDG["s"][i]
						end
					end
					local r = table.concat(stroka)
					SendChatMessage(r .. " " .. "букв: " .. #s, "officer", nil, 1)
					if p == 0 then
						SendChatMessage(sender .. " называет слово целиком!!!", "officer", nil, 1)
						TDG["s"] = {}
						TDG["vik"] = 0
						if TDG["vikUch"] == nil then
							TDG["vikUch"] = {}
						end
						if TDG["vikUch"][sender] == nil then
							TDG["vikUch"][sender] = 5
						else
							TDG["vikUch"][sender] = TDG["vikUch"][sender] + 5
						end
						for k, v in pairs(TDG["vikUch"]) do
							if v >= 0 then
								SendChatMessage(k .. " получает " .. v*10 .. " золота", "officer", nil, 1)
							else
								SendChatMessage(k .. " должен гильдии " .. v*10 .. " золота", "officer", nil, 1)
							end
						end
						TDG["vikUch"] = nil
						TDG["vik"] = nil
						TDG["s"] = nil
						s = nil
						tempB = nil
						TDG["вопрос"] = nil
						r = nil
					end
					if TDG["vikUch"] ~= nil then
						if bally ~= 0 then
							if TDG["vikUch"] == nil then
								TDG["vikUch"] = {}
							end
							if TDG["vikUch"][sender] == nil then
								TDG["vikUch"][sender] = bally
							else
								TDG["vikUch"][sender] = TDG["vikUch"][sender] + bally
							end
						else
							if TDG["vikUch"] == nil then
								TDG["vikUch"] = {}
							end
							if TDG["vikUch"][sender] == nil then
								TDG["vikUch"][sender] = -1
							else
								TDG["vikUch"][sender] = TDG["vikUch"][sender] - 1
							end
						end
						if TDG["vikUch"] ~= nil then
							for k, v in pairs(TDG["vikUch"]) do
								if msg[2] ~= "*" then
									if k == sender then
										SendChatMessage(k .. ": " .. v*10 .. " золота", "officer", nil, 1)
									end
								else
									if TDG["vikUch"][sender] == nil then
										TDG["vikUch"][sender] = 0
									else
										TDG["vikUch"][sender] = tempB
									end
								end
							end
						end
					end
				end
			end
		end
	end
end

if (msg[1] == "!с" or msg[1] == "!слово") and nachaloStr~="*" then
	if TDG["vik"] ~= nil then
		if msg[2] ~= nil then
			if string.len(TDG["vik"]) > 1 then
				if msg[2] == TDG["vik"] then
					SendChatMessage(sender .. " называет слово целиком!!!", "officer", nil, 1)
					if TDG["vikUch"] == nil then
						TDG["vikUch"] = {}
					end
					if TDG["vikUch"][sender] == nil then
						TDG["vikUch"][sender] = 5
					else
						TDG["vikUch"][sender] = TDG["vikUch"][sender] + 5
					end
					TDG["s"] = {}
					TDG["vik"] = 0
					for k, v in pairs(TDG["vikUch"]) do
						if v >= 0 then
							SendChatMessage(k .. " получает " .. v*10 .. " золота", "officer", nil, 1)
						else
							SendChatMessage(k .. " должен гильдии " .. v*10 .. " золота", "officer", nil, 1)
						end
					end
					TDG["vikUch"] = nil
					TDG["vik"] = nil
					TDG["s"] = nil
					s = nil
					tempB = nil
					r = nil
					TDG["вопрос"] = nil
				else
					if TDG["vikUch"] == nil then
						TDG["vikUch"] = {}
					end
					if TDG["vikUch"][sender] == nil then
						TDG["vikUch"][sender] = -5
					else
						TDG["vikUch"][sender] = TDG["vikUch"][sender] - 5
					end
					if TDG["vikUch"] ~= nil then
						for k, v in pairs(TDG["vikUch"]) do
							SendChatMessage(k .. ": " .. v*10 .. " золота", "officer", nil, 1)
						end
					end
				end
			end
		end
	end
end
msg=mysplit(message)
if testHis[1] == "!заметка+" or string.find (message, "#zzu") and nachaloStr~="*" then
	for z=1,GetNumGuildMembers(true) do
		local name, rankName, rankIndex, level, classDisplayName, zone, publicNote, officerNote, isOnline, status, class, achievementPoints, achievementRank, isMobile, canSoR, repStanding, guid = GetGuildRosterInfo(z)
		if name == sender then
			local vzP = (message):gsub("!заметка%+", "");
			vzP=all_trim(vzP)
			local zamDop = publicNote .. " " .. vzP
			GuildRosterSetPublicNote(z, zamDop)
			SendChatMessage("*" .. name .. ", заметка дополнена", "officer", nil, 1)
		end
	end
end

if testGM~=nil then
	if string.find (message, "!удалить ачивку") then
		msg=mysplit(message)
		if msg[5]==nil then
			q=msg[3]
			q=tonumber(q)
			msg=msg[4]
			for key, val in pairs(pQuests[q]) do
				if val==msg then
					table.remove(pQuests[q], key)
					print("*Квест " .. val .. " " .. GetAchievementLink(val) .. " был удален.")
				else
				end
			end
		else
			q=msg[3]
			q=tonumber(q)
			q1=msg[4]
			q1=tonumber(q1)
			msg=msg[5]
			if pQuests[q][q1]==nil then
				pQuests[q][q1]={}
			end
			for key, val in pairs(pQuests[q][q1]) do
				if val==msg then
					table.remove(pQuests[q][q1], key)
					print("*Квест " .. val .. " " .. GetAchievementLink(val) .. " был удален.")
				else
				end
			end
		end
	end
end
if testGM~=nil then
    if msg[1] == "!добавить" and msg[2] == "ачивку" and testGM~=nil then
		soobshenie=mysplit(message)
		if soobshenie[5]==nil then
			urovenQuestov=soobshenie[3]
			urovenQuestov=tonumber(urovenQuestov)
			nomerQuesta=soobshenie[4]
			for key, val in pairs(pQuests[urovenQuestov]) do
				if val==nomerQuesta then
					print("*Ачивка " .. val .. " " .. GetAchievementLink(val) .. " уже была добавлена.")
					testIDqq=1
				else
				end
			end
			if testIDqq~=1 then
				table.insert(pQuests[urovenQuestov], nomerQuesta)
				print("*Ачивка " .. nomerQuesta .. " " .. GetAchievementLink(nomerQuesta) .. " была добавлена.")
			end
		else
			urovenQuestov=soobshenie[3]
			urovenQuestov1=soobshenie[4]
			urovenQuestov=tonumber(urovenQuestov)
			urovenQuestov1=tonumber(urovenQuestov1)
			nomerQuesta=soobshenie[5]
			if pQuests[urovenQuestov][urovenQuestov1] == nil then
				pQuests[urovenQuestov][urovenQuestov1] = {}
			end
			local testIDqq = nil
			for key, val in pairs(pQuests[urovenQuestov][urovenQuestov1]) do
				if val == nomerQuesta then
					print("*Ачивка " .. val .. " " .. GetAchievementLink(val) .. " уже была добавлена.")
					testIDqq = 1
				end
			end
			if testIDqq ~=1 then
				table.insert(pQuests[urovenQuestov][urovenQuestov1], nomerQuesta)
				print("*Ачивка " .. nomerQuesta .. " " .. GetAchievementLink(nomerQuesta) .. " была добавлена.")
			end
		end
	end
end
if msg[1] == "!добавить" and msg[2] == "предмет" and testGM~=nil then
	local nazvanie
	local n
	if pQuests["items"] == nil then
		pQuests["items"] = {}
	end
	if #pQuests["items"] == 0 then
		n = 1
	else
		n = #pQuests["items"]+1
	end
	pQuests["items"][n] = {}
	pQuests["items"][n]["itemNum"] = msg[3]
	pQuests["items"][n]["itemEnStuck"] = msg[4]
	nazvanie = msg[5]
	for i=6,#msg do
		nazvanie = nazvanie .. " " .. msg[i]
	end
	pQuests["items"][n]["itemName"] = nazvanie
	print(pQuests["items"][n]["itemName"] .. " успешно добавлен")
end
if testGM~=nil then
questNaXY=mysplit(message)
if questNaXY[1]=="#zzo" then
	if questNaXY[2]==nil then
		posX, posY = GetPlayerMapPosition("player");
		X={}
		Y={}
		for iX=3,10 do
			X[iX]=string.sub(posX,iX,iX)
			Y[iX]=string.sub(posY,iX,iX)
		end
		mapViz=GetCurrentMapAreaID()
		mioXY=X[3]..Y[3]..X[4]..Y[4]..X[5]..Y[5]..X[6]..Y[6]..X[7]..Y[7]..X[8]..Y[8]..X[9]..Y[9]..X[10]..Y[10]
		sendX,sendY = GetPlayerMapPosition("player");
		kont = GetCurrentMapContinent();
		lok = GetNumMapLandmarks()
	else
		mioXY=questNaXY[2]
		kont = questNaXY[3]
		lok = questNaXY[4]
		mapViz=questNaXY[5]
	end


		hshXY=time()
		hshXY1=string.sub(hshXY,8,8)
		hshXY2=string.sub(hshXY,9,9)
		hshXY3=string.sub(hshXY,10,10)
		local hshXY4 = math.random(0, 9)
		local hshXY5 = math.random(0, 9)
		local hshXY6 = math.random(0, 9)

		hshXY=hshXY1 .. hshXY4 .. hshXY2 .. hshXY5 .. hshXY3 .. hshXY6
		TDG["hshXY"]=hshXY
		SendAddonMessage("NSGadd", "#zzn " .. mioXY .. " " .. kont .. " " .. lok .. " " .. mapViz, "guild")
end

end
end
)
